package com.zis.auction.controller;

import com.alibaba.fastjson.JSONObject;
import com.zis.auction.model.AuctOrg;
import com.zis.auction.service.IAuctOrgInter;
import com.zis.core.SearchParams;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Create by wangshen 2017/12/26
 */
@RestController
@RequestMapping("/api/auction/org")
public class AuctOrgController {

    @Autowired
    private IAuctOrgInter auctOrgInter;


    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public PageQuery<AuctOrg> findByPage(@RequestBody SearchParams params) throws Exception {
        return auctOrgInter.findByPage(params);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public String insert(HttpServletRequest request, @RequestBody AuctOrg auctOrg) throws Exception {
        auctOrg.setCreateUser(request.getAttribute("code").toString());
        return auctOrgInter.insert(auctOrg);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public String update(HttpServletRequest request, @RequestBody AuctOrg auctOrg) throws Exception {
        auctOrg.setUpdateUser(request.getAttribute("code").toString());
        return auctOrgInter.update(auctOrg);
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ResponseBody
    public String delete(@PathVariable("id") String id) throws Exception{
        return auctOrgInter.delete(id);
    }

    @RequestMapping(value = "/select/{id}", method = RequestMethod.GET)
    @ResponseBody
    public AuctOrg select(@PathVariable("id") String id) throws Exception{
        return auctOrgInter.selectById(id);
    }

    @RequestMapping(value = "/options/{type}", method = RequestMethod.GET)
    @ResponseBody
    public List<JSONObject> findAll(@PathVariable("type") String type) throws Exception {
        return auctOrgInter.findOptions(type);
    }
}
